package GUI;

import Model.Attendance;

import javax.swing.table.AbstractTableModel;
import java.util.ArrayList;

public class CourseAttendanceTableModel extends AbstractTableModel {

    private ArrayList<Attendance> data;

    @Override
    public boolean isCellEditable(int row, int column) {
        return false;
    }

    public void setData(ArrayList<Attendance> data)
    {
        this.data = data;
        fireTableDataChanged();
    }

    public ArrayList<Attendance> getData() {
        return data;
    }

    @Override
    public int getColumnCount() {
        return 5;
    }

    @Override
    public int getRowCount()
    {
        if(data == null)
        {
            return 0;
        }
        else
        {
            return data.size();
        }
    }

    @Override
    public String getColumnName(int column) {
        String columnName = "";
        switch(column)
        {
            case 0:
                columnName = "Studie nr.";
                break;
            case 1:
                columnName = "Navn";
                break;
            case 2:
                columnName = "Hold";
                break;
            case 3:
                columnName = "Kommentar";
                break;
            case 4:
                columnName = "Fremmøde";
                break;
        }
        return columnName;
    }


    @Override
    public Object getValueAt(int row, int column)
    {
        Object value = null;
        switch(column)
        {
            case 0:
                value = data.get(row).getStudentId().getStudentNo();
                break;
            case 1:
                value = data.get(row).getStudentId().getName();
                break;
            case 2:
                value = data.get(row).getStudentId().getTeamId().getName();
                break;
            case 3:
                value = data.get(row).getComment();
                break;
            case 4:
                value = data.get(row).getIsAttending();
                break;
        }

        return value;
    }
}
